/*
 * Copyright 2014 by Brian Nguyen (Vietnam)
 * All rights reserved.
 *
 * Author: Centralized Management Solutions
 */
define(['common/constant'], function (constant) {

    // if a global var is defined (most likely from the index.html),
    // replace the URL with this global var
    // can be replaced for production
    var localhost = '';
    if (window.location.hostname == 'localhost') {
    	localhost = '/cms';
    }

    return {
        app: {
            name: 'CMS',
            fullname: 'Centralized Management Solutions',
            version: '0.0.',

            baseUrl: localhost+'/app',
            resourceUrl: localhost+'/resources',
            logoUrl: localhost+'/images/cms.logo.png'
        },

        format: {
            dateDefault:    'DD.MM.YYYY',
            dateHM:         'DD.MM.YYYY HH:mm',

            datePlaceholder:        'DD.MM.YYYY',
            dateAndYearPlaceholder: 'DD.YYYY'
        },
        
        api: {
            baseUrl: localhost+'/api',
            uploadUrl: localhost+'/api/uploadFile',
            defaultListPageSize: 20
        },

        alerts: {
            minTimeout: 3000
        },

        browser: sayWho(),

        i18nOptions: {
            detectFromHeaders: false,
            fallbackLng: constant.DEFAULT_LANGUAGE,
            lng: constant.DEFAULT_LANGUAGE,
            ns: 'cms',
            resGetPath: localhost+'/locales/__ns__.__lng__.json',
            useCookie: false
        },

        toastr: {
            'closeButton': true,
            'debug': false,
            'positionClass': 'toast-bottom-right',
            'onclick': null,
            'showDuration': '300',
            'hideDuration': '1000',
            'timeOut': '3000',
            'extendedTimeOut': '7000',
            'showEasing': 'swing',
            'hideEasing': 'linear',
            'showMethod': 'fadeIn',
            'hideMethod': 'fadeOut'
        }
    };

    /**
     * Helper function to find browser name and version
     */
    function sayWho() {
        var ua = navigator.userAgent, tem,
            M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
        if (/trident/i.test(M[1])) {
            tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
            return 'IE ' + (tem[1] || '');
        }
        if (M[1] === 'Chrome') {
            tem = ua.match(/\bOPR\/(\d+)/);
            if (tem !== null) {
                return 'Opera ' + tem[1];
            }
        }
        M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?'];
        if ((tem = ua.match(/version\/(\d+)/i)) !== null) {
            M.splice(1, 1, tem[1]);
        }

        M[1] = parseInt(M[1], 10) || 0;

        return { type: M[0], version: M[1] };
    }
});